﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FlatRedBall;
using FlatRedBall.Graphics;
using FlatRedBall.Math.Geometry;
using FlatRedBall.Input;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;

using FlatRedBall.Graphics.Animation;

using ROMAP.Utilities;


namespace ROMAP.Entities.Tile
{
    public class ToggleTile : Tile
    {
        #region Fields

        private string contentManagerName;
        private Sprite sprite;
        private int total;
        private bool isCollide;
        private double toggleTime;
        private Boolean visible;

        #endregion

        #region Properties

        #endregion

        #region Methods

        // Constructor
        public ToggleTile(string ContentManagerName)
            : base(ContentManagerName)
        {
            // Set the ContentManagerName and call Initialize:
            contentManagerName = ContentManagerName;

            // If you don't want to add to managers, make an overriding constructor
            Initialize(true);
        }

        protected override void Initialize(bool addToManagers)
        {

            // Here you can preload any content you will be using
            // like .scnx files or texture files.
            if (addToManagers)
            {
                AddToManagers(null);
            }
        }
        public override void AddToManagers(Layer layerToAddTo)
        {
            //SpriteManager.AddPositionedObject(this);
            SpriteManager.AddPositionedObject(this);
            sprite = SpriteManager.AddSprite(@"Content/Obstacles/dirt");

            isCollide = false;
            toggleTime = TimeManager.CurrentTime;

            sprite.AttachTo(this, false);
            sprite.PixelScale();
            sprite.ScaleX = 0.5f;
            sprite.ScaleY = 0.5f;

            Collision = ShapeManager.AddAxisAlignedRectangle();
            Collision.AttachTo(this, false);

            Collision.ScaleX = sprite.ScaleX;
            Collision.ScaleY = sprite.ScaleY;

            Collision.Visible = true;
        }

        public override void Activity()
        {
            if (isCollide)
            {
                if ((int)((TimeManager.CurrentTime - toggleTime) * 10) > (40))
                {
                    Toggled();
                }
            }
        }

        public override void Destroy()
        {
            isCollide = true;
            toggleTime = TimeManager.CurrentTime;
        }

        public override void SetPosition(int x, int y)
        {
            this.X = 2 * x * sprite.ScaleX;
            this.Y = 2 * y * sprite.ScaleY;
        }

        public void Toggled()
        {
            sprite.Visible = false;
        }
    }
}
        #endregion

 	 


